`
https://leetcode.cn/problems/random-pick-index/
`

/**
 * @param {number[]} nums
 */
var Solution = function (nums) {
  this.nums = nums
};

/** 
* @param {number} target
* @return {number}
*/
Solution.prototype.pick = function (target) {
  // 水塘抽样算法
  // 可能无法通过所有测试用例，仅供参考
  let res = 0;
  let cnt = 0
  for (let i = 0; i < this.nums.length; ++i) {
    if (this.nums[i] == target) {
      ++cnt; // 第 cnt 次遇到 target
      if (Math.floor(Math.random() * cnt) === 0) {
        res = i;
      }
    }
  }
  return res;
};

/** 
* Your Solution object will be instantiated and called as such:
* var obj = new Solution(nums)
* var param_1 = obj.pick(target)
*/